package com.kim.client.abs;


import com.kim.common.entity.message.MessageInfo;
import com.kim.client.interfaces.MessageStrategy;
import com.kim.common.enums.GlobalExceptionEnum;
import jakarta.websocket.Session;

import java.util.Optional;

import static com.kim.common.enums.GlobalExceptionEnum.SUCCESS;

public abstract class AbsMessageStrategy implements MessageStrategy {

    @Override
    public GlobalExceptionEnum onMessage(MessageInfo messageInfo, Session session) {
        GlobalExceptionEnum globalExceptionEnum = sendMessageBefore(messageInfo, session);
        if (globalExceptionEnum != null) return globalExceptionEnum;
        GlobalExceptionEnum globalExceptionEnum1 = sendMessage(messageInfo, session);
        if (globalExceptionEnum1 != null) return globalExceptionEnum1;
        GlobalExceptionEnum globalExceptionEnum2 = sendMessageAfter(messageInfo, session);
        if (globalExceptionEnum2 != null) return globalExceptionEnum2;

        return SUCCESS;
    }
    protected abstract GlobalExceptionEnum sendMessage(MessageInfo messageInfo, Session session);

    protected abstract GlobalExceptionEnum sendMessageBefore(MessageInfo messageInfo, Session session);

    protected abstract GlobalExceptionEnum sendMessageAfter(MessageInfo messageInfo, Session session);

}
